package com.tz.controller;

import com.tz.entity.RightControl;
import com.tz.entity.User;
import com.tz.service.RoleService;
import com.tz.util.rotuer.RoteMap;
import com.tz.util.rotuer.Rotuer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttribute;
import org.springframework.web.bind.annotation.SessionAttributes;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Alex
 * @date 18/1/5
 */
@Controller
@RequestMapping("/right")
@SessionAttributes("user")
public class RightController {
    @Autowired
    RoleService roleService;

    @ResponseBody
    @RequestMapping("/init")
    public Map<String, Rotuer> initrotue(@SessionAttribute("user")User user) {
        //从session获取用户权限
        System.out.println(user);
        List<RightControl> list=user.getRole().getUrls();
        Map<String, Rotuer> myRoles=new HashMap<>();
        Map<String, Rotuer> allRoles=RoteMap.getMap();

        for(RightControl rc:list){
                myRoles.put(rc.getUrls(),allRoles.get(rc.getUrls()));
        }
        return  myRoles;
    }
}
